package com.bawei.module_shop.order;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bawei.library_base.RouterPath;
import com.bawei.library_base.mvp.v.BaseActivity;
import com.bawei.library_base.room.good.Good;
import com.bawei.library_base.room.good.GoodDatabase;
import com.bawei.module_shop.R;
import com.bawei.module_shop.address.AddressActivity;

import java.util.ArrayList;
import java.util.List;

@Route(path = RouterPath.OrderGoods.ORDER_GOODS)
public class OrderActivity extends BaseActivity {


    private TextView mSelectShipTv;
    private TextView mShipNameTv;
    private TextView mShipAddressTv;
    private RecyclerView mOrderGoodsRv;
    private TextView mTotalPriceTv;
    private Button mSubmitOrderBtn;


    @Override
    public int beanLayout() {
        return R.layout.activity_order;
    }

    @Override
    public void initView() {

        mSelectShipTv = (TextView) findViewById(R.id.mSelectShipTv);
        mShipNameTv = (TextView) findViewById(R.id.mShipNameTv);
        mShipAddressTv = (TextView) findViewById(R.id.mShipAddressTv);
        mOrderGoodsRv = (RecyclerView) findViewById(R.id.mOrderGoodsRv);
        mOrderGoodsRv.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL));
        mTotalPriceTv = (TextView) findViewById(R.id.mTotalPriceTv);
        mSubmitOrderBtn = (Button) findViewById(R.id.mSubmitOrderBtn);
    }

    @Override
    public void initData() {

        //数据库中的数据
        List<Good> allGood = GoodDatabase.getInstance(this).getGoodDao().getAllGood();

        ArrayList<Good> goods = new ArrayList<>();

        for (int i = 0; i < allGood.size(); i++) {
            if (allGood.get(i).isCheck()){
                goods.add(allGood.get(i));
            }
        }

        //选中的商品
        true_good(goods);

        //选择收货人
        payphone();

        //支付页面
        pay();

        //选择收货人
        receipt();



    }

    private void receipt() {

    }



    private void payphone() {
        mSelectShipTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(OrderActivity.this, AddressActivity.class);
                startActivity(intent);
            }
        });
    }

    private void pay() {
        mSubmitOrderBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                RouterPath
                ARouter.getInstance().build("/pay/Pay")
                        .navigation();
            }
        });
    }

    //选中的商品
    private void true_good(ArrayList<Good> goods) {
        OrderAdapter orderAdapter = new OrderAdapter(goods);
        mOrderGoodsRv.setAdapter(orderAdapter);
    }
}